Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

round the float value before we cast to Int #558

Merged
merged 1 commit into from
Nov 26, 2015

Conversation

liuxuan30
Copy link
Member

Old code will cause the visible index incorrect, smaller by 1.

Int() simply cuts the fractional part, which usually isn't the desired behaviour ;) Int(round(f)) does the job

I met this when that the last label should be year 2015, but it actually shows 2014. It turned out that pt.x is 3.9999999999999987, and Int(pt.x) is 3

More information about the casting can be found here:http://stackoverflow.com/questions/24029917/convert-float-to-int-in-swift

Old code will cause the visible index incorrect, smaller by 1.

Int() simply cuts the fractional part, which usually isn't the desired behaviour ;) Int(round(f)) does the job

I met this when that the last label should be year 2015, but it actually shows 2014. It turned out that pt.x is 3.9999999999999987, and Int(pt.x) is 3

More information about the casting can be found here:http://stackoverflow.com/questions/24029917/convert-float-to-int-in-swift
danielgindi added a commit that referenced this pull request Nov 26, 2015
Fix for rounding error at the edges
@danielgindi danielgindi merged commit f68e007 into ChartsOrg:master Nov 26, 2015
@danielgindi
Copy link
Collaborator

Thanks :-)

danielgindi added a commit to danielgindi/MPAndroidChart that referenced this pull request Nov 26, 2015
@liuxuan30 liuxuan30 deleted the RoundBeforeInt branch November 27, 2015 07:55
regas99 pushed a commit to regas99/MPAndroidChart that referenced this pull request Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants